# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=entt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}"
         "${MINGW_PACKAGE_PREFIX}-${_realname}-docs")
pkgver=3.15.0
pkgrel=1
pkgdesc="A fast and reliable entity-component system (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/skypjack/entt"
license=('spdx:MIT')
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-doxygen"
)
source=("https://github.com/skypjack/entt/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('01466fcbf77618a79b62891510c0bbf25ac2804af5751c84982b413852234d66')

build() {
  mkdir -p "${srcdir}/build-${MSYSTEM}" && cd "${srcdir}/build-${MSYSTEM}"

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DENTT_INSTALL=ON \
      -DENTT_BUILD_DOCS=ON \
      ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake.exe --build .
}

package_entt() {
  cd "${srcdir}"/build-${MSYSTEM}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install .

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE

  # split docs
  mkdir -p "dest${MINGW_PREFIX}/share/doc/"
  mv "${pkgdir}${MINGW_PREFIX}/share/EnTT-${pkgver}" "dest${MINGW_PREFIX}/share/doc/${_realname}"
}

package_entt-docs() {
  pkgdesc+=" (documentation)"
  depends=()

  cd "${srcdir}"/build-${MSYSTEM}

  mv dest/* "${pkgdir}"
}

# template start; name=mingw-w64-splitpkg-wrappers; version=1.0;
# vim: set ft=bash :

# generate wrappers
for _name in "${pkgname[@]}"; do
  _short="package_${_name#${MINGW_PACKAGE_PREFIX}-}"
  _func="$(declare -f "${_short}")"
  eval "${_func/#${_short}/package_${_name}}"
done
# template end;

